Tool

constructor(name: String, description: String, inputSerializer: KSerializer<TInput>, outputSerializer: KSerializer<TOutput>, strict: Boolean = true, inputExamples: List<String> = emptyList(), metadata: Map<String, JsonElement> = emptyMap(), providerExecuted: Boolean = false, providerOptions: Map<String, JsonElement> = emptyMap())

Type Parameters

TInput

Application-defined input type, must be @Serializable. The model produces JSON matching its schema; the agent deserializes via inputSerializer before calling execute.

TOutput

Application-defined output type, must be @Serializable. Serialized into the model's tool-result message via outputSerializer, or summarized via toModelOutput if the raw output would be too verbose for the model.

TContext

Caller-supplied typed context propagated through the whole loop (set via callOptionsSchema, accessed inside execute as this.context).

Internally the agent loop always drives a Flow (the v6 alignment per tool.ts:68-71's AsyncIterable<OUTPUT> shape): a plain Tool wraps its single execute value in a one-emission flow; a StreamingTool passes its Flow straight through. The loop collects with one-step lookahead — non-final emissions become StreamEvent.ToolResult(preliminary = true), the last emission is the final result that lands in the model's message log.